import React from 'react'
import { Form, Input, Button, message } from "antd";
import { LockOutlined, UserOutlined } from "@ant-design/icons";
import axios from "axios";
import styles from "./index.module.less";
import { useNavigate } from "react-router-dom";
import { postLogin } from "@/api/auth";

function Login() {
    const navigate = useNavigate();
    return (
        <div className={styles.login}>
            <div>
                <h1>尚医通管理系统</h1>
                <Form
                    name="normal_login"
                    className="login-form"
                    onFinish={async (values: any) => {
                        // 当用户点击提交，且通过验证以后会执行该函数。
                        // console.log("onFinish",values);
                        console.log(111);
                        
                        const result: any = await postLogin(values);
                        localStorage.setItem("token", result.data.token);
                        navigate("/");
                    }}
                >
                    <Form.Item
                        name="username"
                        rules={[{ required: true, message: '请输入管理员账号' }]}
                    >
                        <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="Username" />
                    </Form.Item>
                    <Form.Item
                        name="password"
                        rules={[{ required: true, message: '请输入管理员账号!' }]}
                    >
                        <Input
                            prefix={<LockOutlined className="请输入管理员密码！" />}
                            type="password"
                            placeholder="请输入管理员密码！"
                        />
                    </Form.Item>

                    <Form.Item>
                        <Button type="primary" htmlType="submit" className="login-form-button">
                            登陆
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        </div>
    )
}
export default Login;
